<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='设备名称'>
              <a-input placeholder='请输入计划名称' v-model='queryParam.shebeiname'></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='设备编号'>
              <a-input placeholder='请输入设备编号' v-model='queryParam.shebeibianhao'></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='保养状态'>
              <j-dict-select-tag type='list' v-model='queryParam.zhuangtai' dictCode='baoyangzhuangtai'
                                 placeholder='请选择所属分组' />
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button type='primary' icon='download' @click="handleExportXls('gd_baoyang_renwu')">导出</a-button>

      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay'>
          <a-menu-item key='1' @click='batchDel'>
            <a-icon type='delete' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a style='font-weight: 600'>{{
          selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table ref='table' size='middle' :scroll='{ x: true }' bordered rowKey='id' :columns='columns'
               :dataSource='dataSource' :pagination='ipagination' :loading='loading'
               :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
               class='j-table-force-nowrap'
               @change='handleTableChange'>
        <template slot='name' slot-scope='text,record'>
          <a v-html='text' @click='handleDetailDrawer(record)'></a>
        </template>
        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text,record'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' :preview='record.id' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button v-else :ghost='true' type='primary' icon='download' size='small' @click='downloadFile(text)'>
            下载
          </a-button>
        </template>

<!--        <span slot="action" slot-scope="text, record">

          <a-divider type="vertical" />
          &lt;!&ndash;          暂定隐藏按钮&ndash;&gt;
          &lt;!&ndash;          <a @click="handleCheck(record)" :disabled="!['待提交'].includes(record.faultRepairState_dictText)"&ndash;&gt;
          &lt;!&ndash;            >提交审核</a&ndash;&gt;
          &lt;!&ndash;          >&ndash;&gt;
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>-->

        <span slot='action' slot-scope='text, record'>
          <a @click="handleDeal(record)" :disabled="['已保养待验收','已验收'].includes(record.zhuangtai_dictText)">保养</a>
          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a @click='handleDetail(record)'>详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>


      </a-table>
    </div>

    <gd-baoyang-renwu-modal ref='modalForm' @ok='modalFormOk'></gd-baoyang-renwu-modal>
    <GdBaoyangGongdanDrawer ref='modalDrawer' />
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import GdBaoyangRenwuModal from './modules/GdBaoyangRenwuModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import editor from '@toast-ui/editor'
import { httpAction } from '@/api/manage'

import GdBaoyangGongdanDrawer from './modules/GdBaoyangGongdanDrawer.vue'

export default {
  name: 'GdBaoyangGongdanList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    GdBaoyangRenwuModal,
    GdBaoyangGongdanDrawer
  },
  data() {
    return {
      description: 'gd_baoyang_renwu管理页面',
      // 表头
      columns: [
        {
          title: '设备名称',
          align: 'center',
          dataIndex: 'shebeiname',
          scopedSlots: { customRender: 'name' }
        },
        {
          title: '计划名称',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '保养层级',
          align: 'center',
          dataIndex: 'cengji_dictText'
        },
        {
          title: '保养方式',
          align: 'center',
          dataIndex: 'fangshi_dictText'
        },
        {
          title: '保养周期（天）',
          align: 'center',
          dataIndex: 'jiangeshichang'
        },
        {
          title: '开始时间',
          align: 'center',
          dataIndex: 'createTime',
/*          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }*/
        },
        {
          title: '预计时间',
          align: 'center',
          dataIndex: 'guoqitianshu',
/*          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }*/
        },
        {
          title: '保养时间',
          align: 'center',
          dataIndex: 'zhixingshijian',
/*          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }*/
        },
        {
          title: '保养状态',
          align: 'center',
          dataIndex: 'zhuangtai_dictText'
        },
        {
          title: '执行人',
          align: 'center',
          dataIndex: 'fuzeren_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/gongdan/gdBaoyangGongdan/list',
        delete: '/gongdan/gdBaoyangRenwu/delete',
        edit: '/gongdan/gdBaoyangRenwu/edit',
        exportXlsUrl: '/gongdan/gdBaoyangRenwu/exportXls',
        importExcelUrl: 'gongdan/gdBaoyangRenwu/importExcel',
        deleteBatch: "/gongdan/gdBaoyangRenwu/deleteBatch",
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    updateStatus(record) {
      this.$http.post('/gongdan/gdBaoyangRenwu/processing', record)
        .then(response => {
          this.$message.success('保养成功')
        })
        .catch(error => {
          this.$message.error('保养失败，请稍后再试')
          console.error('Error sending task:', error)
        })
    },
    handleDetailDrawer(record) {
      this.$refs.modalDrawer.record = record
      this.$refs.modalDrawer.visible = true
    },
    handleDeal(record) {
      this.$refs.modalForm.deal(record)
      this.$refs.modalForm.title = '保养'
      this.$refs.modalForm.disableSubmit = false
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: '计划名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bianhao', text: '计划编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'cengji', text: '保养层级', dictCode: 'baoyangcengji' })
      fieldList.push({ type: 'int', value: 'fangshi', text: '保养方式', dictCode: 'baoyangfangshi' })
      fieldList.push({ type: 'int', value: 'guoqitianshu', text: '过期天数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'jiangeshichang', text: '间隔时长', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'beizhu', text: '备注', dictCode: '' })
      fieldList.push({ type: 'int', value: 'zhuangtai', text: '保养状态', dictCode: 'baoyangzhuangtai' })
      fieldList.push({ type: 'string', value: 'shebeiname', text: '设备名称', dictCode: 'ene_device,name,id' })
      fieldList.push({ type: 'string', value: 'shebeibianhao', text: '设备编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'fuzeren', text: '执行人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'fuzerenXingming', text: '负责人姓名', dictCode: '' })
      fieldList.push({ type: 'date', value: 'zhixingshijian', text: '执行时间' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>